#region Using Statements
using System;
using System.Collections;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
#endregion

namespace SkyBurner.Screens
{
    public enum SkyBurnerScreenID
    {
        sbs_Main,
        sbs_LevelChooser,
        sbs_Game,
        sbs_GameOver,
        sbs_Highscores,
        sbs_Credits,
        sbs_Config
    };

    public partial class ScreenManager : Microsoft.Xna.Framework.DrawableGameComponent
    {
        protected SkyBurnerScreenBase m_activeScreen;
        protected Collection<SkyBurnerScreenBase> m_screenList = new Collection<SkyBurnerScreenBase>();

        public ScreenManager(BaseGame game)
            : base(game)
        {

        }

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            base.Initialize();            
        }

        public void AddScreen(SkyBurnerScreenBase pScreenBase)
        {
            m_screenList.Add(pScreenBase);
        }

        public void ActivateScreen(SkyBurnerScreenID pScreenToActivate)
        {
            foreach (SkyBurnerScreenBase screen in m_screenList)
            {
                if (screen.ID == pScreenToActivate)
                {
                    if (m_activeScreen != null)
                        m_activeScreen.Deactivate();

                    screen.Activate();
                    m_activeScreen = screen;
                }
            }
        }

        public SkyBurnerScreenBase GetScreen(SkyBurnerScreenID pScreenID)
        {
            foreach (SkyBurnerScreenBase screen in m_screenList)
            {
                if (screen.ID == pScreenID)
                    return screen;
            }
            return null;
        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            // update the active screen
            m_activeScreen.Update(gameTime, null);

            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            // draw the active screen
            m_activeScreen.Draw(gameTime, null);

            base.Draw(gameTime);
        }
    }
}
